home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / gfx / fract / FlashMandelWOS.lha / FlashMandel / Developer / Modules / Gfx.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-08-02  |  7.0 KB  |  285 lines

  1. /**********************************************************************************************************
  2. **
  3. **  Coded by Dino Papararo     11-Feb-1999
  4. **
  5. **  FUNCTION
  6. **
  7. **    Fade -- perform screen color fading from/to black.
  8. **
  9. **  SYNOPSIS
  10. **
  11. **    BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG MyTimeDelay,BOOL ToBlack)
  12. **
  13. **  DESCRIPTION
  14. **
  15. **    According with ToBlack value screen will fade from black to PaletteSrc or from PaletteSrc to black.
  16. **
  17. **    MaxStep is number of times colors will be decreased/increased from/to black.
  18. **
  19. **    MyTimeDelay is the wait time between two palette changes, needed for multitasking and faster cpus.
  20. **
  21. **  RETURN
  22. **
  23. **    FALSE if screen propreties not available or Depth < 2 or MaxStep < 2, TRUE color cycling performed.
  24. **
  25. ***********************************************************************************************************
  26. **
  27. **  Coded by Claudio Pucci & Dino Papararo     26-Oct-1997
  28. **
  29. **  FUNCTION
  30. **
  31. **    Cycle -- perform screen color cycling.
  32. **
  33. **  SYNOPSIS
  34. **
  35. **    BOOL Cycle (struct Window *Win,ULONG MyTimeDelay,BOOL Left)
  36. **
  37. **  DESCRIPTION
  38. **
  39. **    Function uses a double sized table to manage color cycling.
  40. **
  41. **    So we do not need to save and shift all colors for every cycle,
  42. **
  43. **    but only save and set correct first and last values !
  44. **
  45. **    This function do not load the first four color registers reserved for GUI pens.
  46. **
  47. **  RETURN
  48. **
  49. **    FALSE if screen propreties not available or Depth < 2, TRUE color cycling performed.
  50. **
  51. **********************************************************************************************************/
  52.  
  53. /* Modified for ARexx-support by E. Schwan 23.1.2002 */
  54.  
  55. #include <exec/types.h>
  56. #include <proto/dos.h>
  57. #include <proto/intuition.h>
  58. #include <proto/graphics.h>
  59. #include <proto/gadtools.h>
  60. #include <intuition/intuition.h>
  61. #include <graphics/gfxbase.h>
  62.  
  63. #include "FlashMandel.h"
  64.  
  65. #define RAW_ESC 0x45
  66.  
  67. #define RESERVED_PENS 4L
  68.  
  69. //#define BLACK 0L
  70.  
  71. //BOOL Fade (struct Window *,ULONG *,ULONG,ULONG,BOOL);
  72. //BOOL Cycle (struct Window *,ULONG,BOOL);
  73.  
  74. BOOL Fade (struct Window *Win,ULONG *PaletteSrc,ULONG MaxStep,ULONG MyTimeDelay,BOOL ToBlack)
  75. {
  76. DisplayInfoHandle DHandle;
  77.  
  78. struct DisplayInfo DInfo;
  79.  
  80. static ULONG PaletteTmp [3L * 252L + 2L];
  81.  
  82. LONG Var,Step;
  83.  
  84. ULONG Range,ModeID;
  85.  
  86. BOOL AllBlack;
  87.  
  88.   if ((Win->RPort->BitMap->Depth < 2L) || (MaxStep < 2L)) return FALSE;
  89.  
  90.   ModeID = GetVPModeID (ViewPortAddress (Win));
  91.  
  92.   DHandle = FindDisplayInfo (ModeID);
  93.  
  94.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  95.   {
  96.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE) Range = 32L - 4L;
  97.  
  98.      else Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  99.  
  100.      PaletteTmp [0L] = (Range << 16L) + 4L;
  101.  
  102.      GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&PaletteTmp [1L]);
  103.  
  104.      PaletteTmp [3L * Range + 1L] = NULL;
  105.  
  106.      if (ToBlack)
  107.      {
  108.         for (Step = 0L; Step <= MaxStep; Step++)
  109.         {
  110.             AllBlack = TRUE;
  111.  
  112.             for (Var = 1; Var <= 3L * Range; Var++)
  113.             {
  114.                 if (PaletteTmp [Var])
  115.                 {
  116.                    PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  117.  
  118.                    AllBlack = FALSE;
  119.                 }
  120.             }
  121.  
  122.             if (AllBlack) break;
  123.  
  124.             WaitTOF ();
  125.  
  126.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  127.  
  128.             Delay (MyTimeDelay);
  129.         }
  130.      }
  131.  
  132.      else
  133.      {
  134.         for (Step = MaxStep; Step >= 0L; Step--)
  135.         {
  136.             for (Var = 1; Var <= 3L * Range; Var++)
  137.  
  138.                 PaletteTmp [Var] = (((PaletteSrc [Var + (3 * RESERVED_PENS)] >> 24L) * (MaxStep - Step)) / MaxStep) << 24L;
  139.  
  140.             WaitTOF ();
  141.  
  142.             LoadRGB32 (ViewPortAddress (Win),PaletteTmp);
  143.  
  144.             Delay (MyTimeDelay);
  145.         }
  146.  
  147.         LoadRGB32 (ViewPortAddress (Win),PaletteSrc);
  148.      }
  149.  
  150.      return TRUE;
  151.   }
  152.  
  153.   return FALSE;
  154. }
  155.  
  156. BOOL Cycle (struct Window *Win,ULONG MyTimeDelay,BOOL Left)
  157. {
  158. DisplayInfoHandle DHandle;
  159.  
  160. struct DisplayInfo DInfo;
  161.  
  162. struct IntuiMessage *Message;
  163.  
  164. static ULONG Palette_Tmp [2L * 3L * 252L + 2L];
  165.  
  166. BOOL Loop = TRUE;
  167.  
  168. UWORD MyCode;
  169.  
  170. ULONG MyClass,Counter = NULL,OldBlue,OldRed,Tmp_1,Tmp_2,HalfRange;
  171.  
  172. ULONG ModeID,Range;
  173.  
  174.   if (Win->RPort->BitMap->Depth < 2L) return FALSE;
  175.  
  176.   ModeID = GetVPModeID (ViewPortAddress (Win));
  177.  
  178.   DHandle = FindDisplayInfo (ModeID);
  179.  
  180.   if (GetDisplayInfoData (DHandle,(UBYTE *) &DInfo,sizeof (struct DisplayInfo),DTAG_DISP,ModeID))
  181.   {
  182.      if (DInfo.PropertyFlags & DIPF_IS_EXTRAHALFBRITE)
  183.      {
  184.         Range = 64L - 8L;
  185.  
  186.         HalfRange = Range >> 1L;
  187.  
  188.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [1L]);
  189.  
  190.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * HalfRange + 1L]);
  191.  
  192.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (2L * HalfRange) + 1L]);
  193.  
  194.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,HalfRange,&Palette_Tmp [3L * (3L * HalfRange) + 1L]);
  195.  
  196.         Palette_Tmp [3L * 2L * (4L * HalfRange) + 1L] = NULL;
  197.      }
  198.  
  199.      else
  200.      {
  201.         Range = (1L << Win->RPort->BitMap->Depth) - 4L;
  202.  
  203.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [1L]);
  204.  
  205.         GetRGB32 (ViewPortAddress (Win)->ColorMap,4L,Range,&Palette_Tmp [3L * Range + 1L]);
  206.  
  207.         Palette_Tmp [2L * 3L * Range + 1L] = NULL;
  208.      }
  209.  
  210.      Palette_Tmp [0L] = (Range << 16L) + 4L;
  211.  
  212.      if (! Left) Counter = Range + 1L;
  213.  
  214.      while (Loop)
  215.      {
  216.            if (Win->UserPort->mp_SigBit)
  217.            {
  218.               if (Message = (struct IntuiMessage *) GT_GetIMsg (Win->UserPort))
  219.               {
  220.                  MyClass = Message->Class;
  221.  
  222.                  MyCode  = Message->Code;
  223.  
  224.                  GT_ReplyIMsg ((struct IntuiMessage *) Message);
  225.  
  226.                  switch (MyClass)
  227.                  {
  228.                     case IDCMP_MOUSEBUTTONS:  if (MyCode == SELECTDOWN) Loop = FALSE;
  229.  
  230.                                               break;
  231.  
  232.                     case IDCMP_MENUPICK    :  Loop = FALSE;
  233.  
  234.                                               break;
  235.  
  236.                     case IDCMP_RAWKEY      :  if (MyCode == RAW_ESC) Loop = FALSE;
  237.  
  238.                                               break;
  239.                  }
  240.               }
  241.            }
  242.  
  243.            if (Left)
  244.            {
  245.               Counter++;
  246.  
  247.               if (Counter > Range) Counter = 1L;
  248.            }
  249.  
  250.            else
  251.            {
  252.               Counter--;
  253.  
  254.               if (Counter < 1L) Counter = Range;
  255.            }
  256.  
  257.            Tmp_1 = 3L * Counter;
  258.  
  259.            Tmp_2 = 3L * (Counter + Range) + 1L;
  260.  
  261.            OldBlue = Palette_Tmp [Tmp_1];
  262.  
  263.            OldRed  = Palette_Tmp [Tmp_2];
  264.  
  265.            Palette_Tmp [Tmp_1] = (Range << 16L) + 4L;
  266.  
  267.            Palette_Tmp [Tmp_2] = NULL;
  268.  
  269.            WaitTOF ();
  270.  
  271.            LoadRGB32 (ViewPortAddress (Win),&Palette_Tmp [3L * Counter]);
  272.  
  273.            Delay (MyTimeDelay);
  274.  
  275.            Palette_Tmp [Tmp_1] = OldBlue;
  276.  
  277.            Palette_Tmp [Tmp_2] = OldRed;
  278.      }
  279.  
  280.      return TRUE;
  281.   }
  282.  
  283.   return FALSE;
  284. }
  285.